﻿using CoreComponents.DataAccess;
using Crowler.Model.CoreComponents.DataAccess;
using NHibernate.Cfg;
using NHibernate.Dialect;
using NHibernate.Driver;

namespace Crowler.TestBase
{
    public class NHibernateTestConfigurationProvider:INHibernateConfigurationProvider
    {
        public Configuration CreateNHibernateConfiguration()
        {
            var configuration = new Configuration()
                .SetProperty(Environment.ReleaseConnections, "on_close")
                .SetProperty(Environment.ConnectionDriver, typeof (SQLite20Driver).AssemblyQualifiedName)
                .SetProperty(Environment.ConnectionProvider,
                             "NHibernate.Connection.DriverConnectionProvider")
                .SetProperty(Environment.Isolation, "ReadCommitted")
                .SetProperty(Environment.ConnectionString, "Data Source=:memory:;Version=3;New=True;")
                .SetProperty(Environment.ShowSql, "True")
                .SetProperty(Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle")
                .SetProperty(Environment.Dialect, typeof (SQLiteDialect).AssemblyQualifiedName);
            foreach (var assembly in SolutionAssemblies.GetAssemblies())
            {
                configuration.AddAssembly(assembly);
            }
            return configuration;
        }
    }
}
